package database;

public class Account {
	private String type; // type of account
	private double availableBalance; // funds available for withdrawal
	private double totalBalance; // funds available + pending deposits +
									// overdraft
	private double interest;// accounts interest
	private double overdraft;// accounts overdraft

	// Account constructor initializes attributes
	public Account(String theType, double theAvailableBalance,
			double theTotalBalance, double theInterest, double theOverdraft) {
		type = theType;
		availableBalance = theAvailableBalance;
		totalBalance = theTotalBalance;
		interest = theInterest;
		overdraft = theOverdraft;

	} // end Account constructor
 
	// return  account type
	public String getType() {
		return type;
	}// end method getType

	// return overdraft
	public double getOverdraft() {
		return overdraft;
	}// end method getOverdraft

	// return interest
	public double getInterest() {
		return interest;
	} // end method getInterest

	// returns  available balance
	public double getAvailableBalance() {
		return availableBalance;
	} // end getAvailableBalance

	// returns total balance
	public double getTotalBalance() {
		return totalBalance;
	} // end method getTotalBalance

	// credits an amount to the account
	public void credit(double amount) {
		totalBalance += amount; // add to total balance
	} // end method credit

	// debits an amount from the account
	public void debit(double amount) {
		availableBalance -= amount; // subtract from available balance
		totalBalance -= amount; // subtract from total balance
	} // end method debit

	// adding interest to accounts
	public void addInterestToCash() {

		// if account has negative balance, the interest will increase
		if (availableBalance < 0) {
			interest = interest + 12.5;
		}// end if statement

		// x equals the interest in amount for the available balance
		double x = (availableBalance * Math.pow((1 + (interest / 100)), 1))
				- availableBalance;

		// if available balance is higher than 0 add x to available and total
		// balance
		// else subtract x to available and total balance
		if (availableBalance >= 0) {
			availableBalance += x;
			totalBalance += x;
		}// end if statement
		else {
			availableBalance -= x;
			totalBalance -= x;
		}// end else statement

	}// end addInterestToCash method

}// end Account class